package com.easyattendance.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.easyattendance.model.Student;
import com.easyattendance.model.StudentLeave;
import com.easyattendance.services.AddClassService;
import com.easyattendance.services.AddTeacherService;
import com.easyattendance.services.AttendanceService;


@WebServlet(name="AttendanceServlet",urlPatterns="/AttendanceServlet")
public class AttendanceServlet extends HttpServlet{
	
	public AttendanceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
    		
    	 	response.setContentType("text/html;charset=UTF-8");
    		PrintWriter out = response.getWriter();
		
    		/* Get students list  */
    		AttendanceService service = new AttendanceService();
    		
    		ArrayList<Student> getStudList=service.getStudentList(request.getParameter("classid"));
    		request.getSession().setAttribute("student_list", getStudList);
    		request.getSession().setAttribute("classid",request.getParameter("classid")); 
    			
    		ArrayList<StudentLeave> getStudLeaves=service.getStudentLeaveList(request.getParameter("classid"));
    		request.getSession().setAttribute("leave_list",getStudLeaves);
    		
    		
    		
    		/*RequestDispatcher requetsDispatcherObj =request.getRequestDispatcher("views/teacher/viewAttendanceStudentList.jsp");
    		System.out.println("Dispatching....");
    		requetsDispatcherObj.forward(request, response);  */
    		response.sendRedirect("views/teacher/viewAttendanceStudentList.jsp");
    		
    		
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
}
